package com.wbk.lotterysystemlotteryservice.controller;

import com.github.pagehelper.PageInfo;
import com.wbk.lotterysystemlotteryservice.commons.bo.LotteryJoinBO;
import com.wbk.lotterysystemlotteryservice.commons.dto.LotteryDTO;
import com.wbk.lotterysystemlotteryservice.controller.biz.LotteryInfoBiz;
import com.wbk.lotterysystemlotteryservice.entity.Record;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import result.Result;

import javax.validation.Valid;

@Api
@RestController
@RequestMapping("/lottery/api/lottery")
public class LotteryInfoController {

    @Autowired
    LotteryInfoBiz lotteryInfoBiz;

    @ApiOperation(value = "抽奖活动列表接口", notes = "抽奖活动列表")
    @GetMapping("/lotteryList")
    public Result<PageInfo> lotteryList(@ApiParam(value = "当前页") @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                        @ApiParam(value = "每页的记录数") @RequestParam(value = "pageSize", defaultValue = "4") Integer pageSize,
                                        @ApiParam(value = "连续显示多少页") @RequestParam(value = "navigatePages", defaultValue = "5") Integer navigatePages) {
        return lotteryInfoBiz.lotteryList(pageNum, pageSize, navigatePages);
    }

    @ApiOperation(value = "查看抽奖活动接口", notes = "查看抽奖活动")
    @GetMapping("/getLottery/{id}")
    public Result<LotteryDTO> getLottery(@PathVariable("id") Integer id) {
        return lotteryInfoBiz.getLottery(id);
    }

    @ApiOperation(value = "查看当前时间是否有效接口",notes = "查看当前时间是否有效")
    @GetMapping("/isEffectiveTIme/{id}")
    public Result isEffectiveTIme(@PathVariable("id") Integer id){
        return lotteryInfoBiz.isEffectiveTIme(id);
    }

    @ApiOperation(value = "报名参加抽奖接口",notes = "报名参加抽奖")
    @PostMapping("/join")
    public Result<Record> join(@Valid @RequestBody LotteryJoinBO lotteryJoinBO){
        return lotteryInfoBiz.join(lotteryJoinBO);
    }

    @ApiOperation(value = "报名人数接口",notes = "报名人数")
    @GetMapping("/numbers/{id}")
    public Integer numbers(@PathVariable("id")Integer id){
        return lotteryInfoBiz.numbers(id);
    }

}
